#include <stdio.h>
#include <string.h>

#define NAME_MAX_LENGTH 50

// 学生结构体
typedef struct {
    char name[NAME_MAX_LENGTH];
    int age;
} Student;

// 初始化学生对象
void initStudent(Student* student) {
    strcpy(student->name, "无名"); // 默认姓名
    student->age = 7;               // 默认年龄
}

// 设置姓名
void setName(Student* student, const char* name) {
    strncpy(student->name, name, NAME_MAX_LENGTH - 1);
    student->name[NAME_MAX_LENGTH - 1] = '\0'; // 确保字符串结尾
}

// 设置年龄
void setAge(Student* student, int age) {
    student->age = (age <= 6) ? 7 : age;
}

// 显示学生信息
void displayStudent(const Student* student) {
    printf("姓名: %s, 年龄: %d\n", student->name, student->age);
}

int main() {
    Student student1;
    initStudent(&student1); // 初始化第一个学生
    displayStudent(&student1); // 显示第一个学生信息

    char name[NAME_MAX_LENGTH];
    int age;

    while (1) {
        printf("请输入学生姓名和年龄（输入exit退出）: ");
        scanf("%s", name);
        if (strcmp(name, "exit") == 0) {
            break; // 退出循环
        }
        scanf("%d", &age);

        Student student2;
        initStudent(&student2); // 初始化第二个学生
        setName(&student2, name);
        setAge(&student2, age);
        displayStudent(&student2); // 显示第二个学生信息
    }

    return 0;
}
